<?php  
$scriptname= $_POST['ScriptName'];
$uid= $_POST['Uid'];
$description= $_POST['Description'];
$tags= $_POST['Tags'];
$conn=mysql_connect("localhost:3306", "root", "root") or die("ERROR: Cannot open database");
$db = "footprintdb";
mysql_select_db($db) or die("ERROR: Cannot open database");
date_default_timezone_set('Hongkong');
$date = date('m/d/Y h:i:s a', time());
$sql="INSERT INTO scripttable (ScriptName, UsrID, Description, Tag, Date) 
	VALUES 
	('$scriptname', '$uid' ,'$description', '$tags', '$date' )";
mysql_query ( $sql ) or die ( "Error in query execution. ");
$scriptid=mysql_insert_id();
mysql_close($conn);  

mkdir("./".$uid."/".$scriptid,0777);
chmod("./".$uid."/".$scriptid,0777) ;
$fp = fopen("./".$uid."/".$scriptid."/data.xml", "w");  
chmod("./".$uid."/".$scriptid."/data.xml", 0777) ;                     
fwrite($fp, "<?xml version='1.0' encoding='utf-8'?>\n"); 
fwrite($fp, "<root>\n");
fwrite($fp, "</root>\n");                 
fclose($fp);  
$reply=array(
			'scriptid'=>$scriptid,
			'scriptname'=>$scriptname,
			'uid'=>$uid
			);  
echo json_encode($reply);                    
?>  